package com.creating.mict.service.impl;



import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.creating.mict.common.DateUtils;
import com.creating.mict.common.RandomColor;
import com.creating.mict.dao.MessDao;
import com.creating.mict.dao.XyjDao;
import com.creating.mict.domain.MessSend;
import com.creating.mict.domain.Patient;
import com.creating.mict.domain.ReportData;
import com.creating.mict.domain.XyjRecord;
import com.creating.mict.service.ILisService;
import com.creating.mict.service.IMessService;


/**
 * @ClassName: ColumnServiceImpl
 * @Description: 栏目service实现类
 * @author xuelei
 * @date 2012-3-9 下午7:57:34
 * 
 */
public class MessServiceImpl implements IMessService {

	private static final Log log = LogFactory.getLog(MessServiceImpl.class);
	
	@Resource
	private MessDao messDao;
	
	/**
	 * 
	* @Title: saveMessSend 
	* @Description: 保存短信发送记录
	* @param @param loginName
	* @param @param fphone
	* @param @param fcontent
	* @param @param freceiver
	* @param @param ftype
	* @param @return 
	* @return boolean    返回类型 
	* @throws
	 */
	public boolean saveMessSend(String loginName, String fphone, String fcontent, String freceiver, String ftype) {
		String[] fphoneStr = fphone.split(";");
		DateUtils opDate = new DateUtils();
		List<MessSend> list = new ArrayList<MessSend>();
		for(int i = 0; i < fphoneStr.length; i++) {
			if( fphoneStr[i] != null && !(fphoneStr[i].equals("")) ) {
				MessSend messSend = new MessSend();
				messSend.setFid(opDate.getTransactionIdByLongTime());
				messSend.setFdate(new Date());
				messSend.setFcontent(fcontent);
				messSend.setFphone(fphoneStr[i]);
				messSend.setFsender(loginName);
				messSend.setFreceiver(freceiver);
				messSend.setFtype(ftype);
				messSend.setFstate("1");
				
				list.add(messSend);
			}
		}
		log.info(loginName + "保存短信发送记录！");
		return messDao.saveMessSend(list);
	}
	
	
	
	public String queryRMessCountToChart(String fbtime, String fetime, String ftjlx, String loginName) {
		
		List<ReportData> list = new ArrayList<ReportData> ();
		
		list = messDao.queryRMessCountToChart(fbtime, fbtime, ftjlx, loginName);
		
		DateUtils op_date = new DateUtils();
		String img_name = op_date.getTransactionIdByTime();
		RandomColor rc = new RandomColor();
		
		//图表xml字符串
		StringBuffer xmlStr = new StringBuffer("");
		xmlStr.append("<chart  bgColor='EEEEEE' baseFontSize='12' chartTopMargin='5' chartBottomMargin='30' decimalPrecision='0' forceDecimals='0' decimals='2' showNames='1' formatNumberScale='0' caption='" 
		+ "' subcaption='' "
		+ " baseFont='宋体' useRoundEdges='1' yAxisName='' canvasBorderThickness='1' numberPrefix=''  exportFormats='JPEG=导出JPG图片|PNG=导出PNG图片' exportEnabled='1' exportAction='download' exportFileName='" + img_name + "' exportHandler='FCExporter' >");
		
		
		
		
		xmlStr.append("</chart>");
		
		
		return "" + xmlStr + "$$";
		
	} 
	
	
	

}
